package com.bt.lms.ui.page.teaching.plan;


import com.bt.lms.ui.action.teaching.plan.LRelevanceCourseReturnBtnAction;
import com.bt.lms.ui.action.teaching.plan.LRelevanceCourseSaveBtnAction;
import com.bt.lms.ui.vo.teachingplan.RelevanceCourse;
import com.bt.lms.ui.vo.teachingplan.TeachingPlanVo;
import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;

import java.util.ArrayList;
import java.util.List;


/**
 * 教学计划
 * 新增关联课程界面
 */
public class PageRelevanceCourse extends VBox {

    /**
     * 宽
     */
    public Integer preWidth = 1280;
    /**
     * 列名固定宽
     */
    private double columnWidth = 202;


    /**
     * 关联课程
     */
    public PageRelevanceCourse(){


        //初始化所在位置
        initLocation();
        //设置内间距
        Insets insets = new Insets(10);
        this.setPadding(insets);

        this.setPrefWidth(preWidth);

        //大标签
        HBox hBox = new HBox();
        hBox.setPadding(insets);
        hBox.setAlignment(Pos.CENTER_LEFT);
        Label label = new Label("增加关联课程");
        Font font = Font.font("仿宋", FontWeight.THIN, FontPosture.REGULAR,15);
        label.setFont(font);
        hBox.getChildren().add(label);
        this.getChildren().add(hBox);

        //初始化分页条件查询
        initPagingConditionQuery();
        //初始化表格
        initTable();
        //初始化保存按钮
        initSaveButton();



    }

    /**
     * 初始化所在位置
     */
    public void initLocation(){

        HBox hBox = new HBox();
        Insets insets = new Insets(10);
        hBox.setPadding(insets);
        Label label = new Label("当前位置：🏠>教学管理>教学计划>新增关联课程");
        Font font = Font.font("仿宋", FontWeight.THIN, FontPosture.REGULAR,18);
        label.setFont(font);
        hBox.getChildren().add(label);
        this.getChildren().add(hBox);

    }


    /**
     * 初始化分页条件查询
     */
    public void initPagingConditionQuery(){

        //盒子
        HBox hBox = new HBox();
        Insets insets = new Insets(10);
        hBox.setPadding(insets);
        hBox.setSpacing(10);

        //标签和下拉框和文本框
        Label belongToCollegeLabel = new Label("所属的学习中心");

        ComboBox<String> courseOpenUnitComboBox = new ComboBox<>();
        courseOpenUnitComboBox.setCursor(Cursor.HAND);
        courseOpenUnitComboBox.getSelectionModel().select("所属的学习中心");
        courseOpenUnitComboBox.getItems().add("清华大学");
        courseOpenUnitComboBox.getItems().add("北京师范大学");
        courseOpenUnitComboBox.getItems().add("山西理工大学");
        courseOpenUnitComboBox.getItems().add("麻省理工大学");

        //适合层次
        Label applyLevelLabel = new Label("适合层次");

        ComboBox<String> applyLevelComboBox = new ComboBox<>();
        applyLevelComboBox.setCursor(Cursor.HAND);
        applyLevelComboBox.getSelectionModel().select("适合层次");
        applyLevelComboBox.getItems().add("免费师范生");
        applyLevelComboBox.getItems().add("免费师范生硕士");
        applyLevelComboBox.getItems().add("职后教育");
        applyLevelComboBox.getItems().add("其他");


        //搜索框
        Label relevanceCourseLabel = new Label("课程编号/课程名称");

        TextField relevanceCourseTF = new TextField();
        relevanceCourseTF.setPromptText("输入文字模糊查询");

        //搜索按钮
        Button searchBtn = new Button("搜索");
        searchBtn.setCursor(Cursor.HAND);

        //标签，下拉框，搜索框，按钮放盒子里
        ObservableList<Node> hBoxChildren = hBox.getChildren();
        hBoxChildren.addAll(belongToCollegeLabel,courseOpenUnitComboBox,applyLevelLabel,
                applyLevelComboBox,relevanceCourseLabel,relevanceCourseTF,searchBtn);

        //放入主盒子
        ObservableList<Node> children1 = this.getChildren();
        children1.add(hBox);

    }


    /**
     * 初始化表格
     */
    public void initTable(){

        //创建表格组件
        TableView tableView = new TableView();
        //创建列头
        TableColumn checkBoxCol = new TableColumn<>();
        TableColumn courseNumberCol = new TableColumn<>("课程编号");
        courseNumberCol.setPrefWidth(columnWidth);
        TableColumn courseNameCol = new TableColumn<>("课程名称");
        courseNameCol.setPrefWidth(columnWidth);
        TableColumn courseOpenUnitCol = new TableColumn<>("所属的学习中心");
        courseOpenUnitCol.setPrefWidth(columnWidth);
        TableColumn applyLevelCol = new TableColumn<>("适用层次");
        applyLevelCol.setPrefWidth(columnWidth);

        //把列头放入表内
        ObservableList columns = tableView.getColumns();
        columns.addAll(checkBoxCol,courseNumberCol,courseNameCol,courseOpenUnitCol,applyLevelCol);
        //盒子
        CheckBox checkBox0 = new CheckBox();
        CheckBox checkBox1 = new CheckBox();
        CheckBox checkBox2 = new CheckBox();

        //表格中加入数据【集合】
        RelevanceCourse relevanceCourse = new RelevanceCourse(checkBox0,"001","java","清华大学",
                "免费师范生");
        RelevanceCourse relevanceCourse1 = new RelevanceCourse(checkBox1,"001","java","清华大学",
                "免费师范生");
        RelevanceCourse relevanceCourse2 = new RelevanceCourse(checkBox2,"001","java","清华大学",
                "免费师范生");
        List<Object> relevanceCourseList = new ArrayList<>();//教学计划集合
        relevanceCourseList.add(relevanceCourse);
        relevanceCourseList.add(relevanceCourse1);
        relevanceCourseList.add(relevanceCourse2);

        //将关联课程列表数据集合转换成Javafx组件集合
        ObservableList<Object> objects = FXCollections.observableArrayList(relevanceCourseList);
        //把数据放入表格当中
        tableView.setItems(objects);

        //配置列映射，让每一列知道要展示的属性是哪一个
        checkBoxCol.setCellValueFactory(new PropertyValueFactory<TeachingPlanVo,Integer>("checkBox"));
        courseNumberCol.setCellValueFactory(new PropertyValueFactory<TeachingPlanVo,Integer>("courseNumber"));
        courseNameCol.setCellValueFactory(new PropertyValueFactory<TeachingPlanVo,String>("courseName"));
        courseOpenUnitCol.setCellValueFactory(new PropertyValueFactory<TeachingPlanVo,String>("courseOpenUnit"));
        applyLevelCol.setCellValueFactory(new PropertyValueFactory<TeachingPlanVo,String>("applyLevel"));



        //把表放到盒子里
        ObservableList<Node> children = this.getChildren();
        children.add(tableView);


    }

    /**
     * 初始化保存按钮
     */
    public void initSaveButton(){

        //按钮小盒子
        HBox hBox = new HBox();
        hBox.setSpacing(10);
        hBox.setAlignment(Pos.CENTER);


        Button saveBtn = new Button("保存并返回");
        saveBtn.setCursor(Cursor.HAND);
        BtnStyle.saveBtn(saveBtn);
        LRelevanceCourseSaveBtnAction relevanceCourseSaveBtnAction = new LRelevanceCourseSaveBtnAction(this);
        saveBtn.setOnAction(relevanceCourseSaveBtnAction);
        Button returnBtn = new Button("返回");
        returnBtn.setCursor(Cursor.HAND);
        BtnStyle.cancelBtn(returnBtn);
        LRelevanceCourseReturnBtnAction relevanceCourseReturnBtnAction = new LRelevanceCourseReturnBtnAction(this);
        returnBtn.setOnAction(relevanceCourseReturnBtnAction);
        //放入按钮盒子
        hBox.getChildren().addAll(saveBtn,returnBtn);

        //放入大盒子
        this.getChildren().add(hBox);

    }




}
